/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// pwindow.hpp - Basic window class definition.
//
// Author: Kenneth G. Maxwell
//
// Copyright (c) 1997-2000 Swell Software
//              All Rights Reserved.
//
// Unauthorized redistribution of this source code, in whole or part,
// without the express written permission of Swell Software
// is strictly prohibited.
//
// Notes:
//
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

#ifndef _PEGWINDOW_
#define _PEGWINDOW_


class PegDecoratedWindow;    // forward reference

/*--------------------------------------------------------------------------*/
// Move Types. A re-size is treated by Peg as simply a different type
// of move.

#define PMM_MOVEALL         0x80
#define PMM_MOVETOP         0x01
#define PMM_MOVEBOTTOM      0x02
#define PMM_MOVELEFT        0x04
#define PMM_MOVERIGHT       0x08
#define PMM_MOVEUR          0x09
#define PMM_MOVELR          0x0a
#define PMM_MOVEUL          0x05
#define PMM_MOVELL          0x06

/*--------------------------------------------------------------------------*/
// Border Width in pixels for PegBorder Objects
// Note: Value must be >= 3 for correct operation
/*--------------------------------------------------------------------------*/
#ifndef PEG_FRAME_WIDTH
#define PEG_FRAME_WIDTH 5
#else
#if !(PEG_FRAME_WIDTH >= 3)
#undef PEG_FRAME_WIDTH
#define PEG_FRAME_WIDTH 3
#endif
#endif

#if defined(PEG_MULTIPLE_SURFACES)

enum PegWindowBlendModes {

    BLEND_MODE_NONE = 0,
    BLEND_MODE_OVERLAY,
    BLEND_MODE_ALPHA
};

#endif

#define MAX_BLEND_RATIO 255


#ifdef PEG_PRO
/*--------------------------------------------------------------------------*/
// Transitions: To move windows on and off the screen
/*--------------------------------------------------------------------------*/
#define TRANSITION_TIMER 1001

/*--------------------------------------------------------------------------*/
enum PEG_WIN_TRANS_MODES
{
    TRANSITION_MODE_NONE = 0,
    TRANSITION_MODE_SLIDE_LEFT,
    TRANSITION_MODE_SLIDE_RIGHT,
    TRANSITION_MODE_SLIDE_UP,
    TRANSITION_MODE_SLIDE_DN,
    TRANSITION_MODE_FADE_IN,
    TRANSITION_MODE_FADE_OUT
};

/*--------------------------------------------------------------------------*/
enum PEG_WIN_TRANS_STATES
{
    TRANSITION_STATE_NONE = 0,
    TRANSITION_STATE_ENTERING,
    TRANSITION_STATE_EXITING
};

/*--------------------------------------------------------------------------*/
struct PegTransControl {
    PEGINT XStep;
    PEGINT YStep;
    PegPoint TargetPos;
    PEGUBYTE EnterMode;
    PEGUBYTE ExitMode;
    PEGUBYTE ActiveMode;
    PEGUBYTE State;
    PEGUBYTE Steps;
    PEGUBYTE Timer;
    PEGUBYTE BeginAlpha;
    PEGUBYTE EndAlpha;
    PEGINT   HardSurface;
    PEGBOOL  DestroyOnExit;
};

#endif // PEG_PRO

/*--------------------------------------------------------------------------*/

class PegWindow : public PegTextThing
{
    friend class PegScreen;

    public:
        PegWindow(const PegRect &Rect, PEGULONG Style = FF_THICK);
        PegWindow(PEGULONG Style = FF_THICK);
        virtual ~PegWindow();

        virtual void Add(PegThing *Who, PEGBOOL Show = TRUE);
        virtual void AddIcon(PegIcon *pIcon);

       #ifdef PEG_PRO
        virtual void BeginEnterTransition(void);
        virtual void BeginExitTransition(void);
       #endif

       #if defined(PEG_MULTIPLE_SURFACES)
        PEGUBYTE BlendMode(void){return mBlendMode;}
        PEGUBYTE BlendRatio(void) {return mBlendRatio;}
       #endif

        PEGBOOL CheckAutoScroll(void);
        virtual PegScroll *CreateHScroll() { return new PegHScroll(); }
        virtual PegScroll *CreateVScroll() { return new PegVScroll(); }

        PEGUBYTE CurrentMoveMode(void) {return mMoveMode;}

        virtual void Draw(const PegRect &Invalid);
        virtual void DrawFrame(PEGBOOL Fill = TRUE);
        virtual PEGINT Execute(PEGBOOL AutoAdd = TRUE);

        virtual void GetHScrollInfo(PegScrollInfo *Put);
        virtual PEGUINT GetIcon(void) {return mIcon;}
        virtual PEGUBYTE GetScrollMode(void) {return mScrollMode;}
        virtual void GetVScrollInfo(PegScrollInfo *Put);

       #ifdef PEG_MULTITHREAD
        PEGINT GlobalModalExecute(void);
       #endif

        virtual void InitClient(void);
        PEGBOOL IsMaximized(void) { return(mMaximized ? TRUE : FALSE); }
        PEGBOOL IsModal(void) { return(mModal ? TRUE : FALSE); }
        virtual PEGINT Message(const PegMessage &Mesg);
        virtual void Resize(const PegRect &NewSize);

       #if defined(PEG_MULTIPLE_SURFACES)
        PEGBOOL SetBlendMode(PEGUBYTE Mode, PEGUBYTE Ratio = 0);

        void SetBlendRatio(PEGUBYTE Ratio)
        {
            mBlendRatio = Ratio;

            if (mSurface > 0)
            {
                Screen()->SetSurfaceAlpha(mSurface, Ratio);
            }
        }

        void SetBlendSurface(PEGINT Surface) { mBlendSurface = Surface; }
       #endif

       #ifdef PEG_PRO
        void SetTransitionMode(PEGUBYTE EnterMode,
             PEGUBYTE ExitMode = TRANSITION_MODE_NONE,
             PEGUBYTE Steps = 8, PEGUBYTE Timer = 1,
             PEGUBYTE BeginAlpha = 24, PEGUBYTE EndAlpha = MAX_BLEND_RATIO,
             PEGBOOL DestroyOnExit = TRUE, PEGINT HardSurface = -1);
       #endif

        virtual void SetIcon(PEGUINT BitmapId) {mIcon = BitmapId;}
        virtual void SetScrollMode(PEGUINT Mode);
        virtual void SetWallpaper(PEGINT Wallpaper, PEGUBYTE Tile = 1)
        {
            mWallpaper = Wallpaper;
            mpWallpaper = NULL;
            mTileFill = Tile;
            Invalidate();
        }

        virtual void SetWallpaper(PegBitmap *pWallpaper, PEGUBYTE Tile = 1)
        {
            mWallpaper = 0;
            mpWallpaper = pWallpaper;
            mTileFill = Tile;
            Invalidate();
        }

    protected:

        virtual PEGUBYTE BorderContains(PegPoint Point);
        void CheckMove(const PegMessage &InMesg);
        void CheckResizeRect(PegRect &Rect);

       #ifdef PEG_PRO
        virtual void DoTransition(void);
       #endif

       #ifdef PEG_PRO
        virtual void EnterTransitionComplete(void) {}
        virtual void ExitTransitionComplete(void);
       #endif

        void FillScrollCorner(void);
        virtual void MoveClientObjects(PEGINT xShift, PEGINT yShift,
                                       PEGBOOL Redraw = TRUE);

        void SurfaceChange(void);

        PegPoint mStartMove;
        PegPoint mMovePoint;
        PegRect mRestore;

        PegScroll *mpVScroll;
        PegScroll *mpHScroll;

       #ifdef PEG_PRO
        PegTransControl *mpTransControl;
       #endif

        PegBitmap *mpWallpaper;
        PEGUINT mWallpaper;
        PEGUINT mIcon;

       #ifdef PEG_MULTIPLE_SURFACES
        PEGINT   mBlendSurface;
        PEGUBYTE mBlendMode;
        PEGUBYTE mBlendRatio;
       #endif

        PEGUBYTE mModal;
        PEGUBYTE mMaximized;
        PEGUBYTE mMoveFrame;
        PEGUBYTE mTileFill;
        PEGUBYTE mScrollMode;
        PEGUBYTE mMoveMode;
        PEGUBYTE mShowPointer;
};


#endif

